package com.sc;

import com.alibaba.druid.pool.DruidDataSource;
import com.sc.utils.DataSourceConfig;
import com.sc.utils.SqlSessionFactoryUtils;
import org.apache.ibatis.datasource.pooled.PooledDataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.sql.*;



public class Test {
    public static void main(String args[]) {
        Connection conn;
        try {
            SqlSessionFactory factory = SqlSessionFactoryUtils.getSqlSessionFactory();
            AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DataSourceConfig.class);
            DruidDataSource d = ctx.getBean("dataSource",DruidDataSource.class);
            try {
                conn = d.getConnection();
                System.out.println("conn = " + conn);
                String sql = "select * from user";
                Statement stmt = conn.createStatement();
                ResultSet rs = stmt.executeQuery(sql);

                while (rs.next()) {
                    System.out.println(rs.getString(1));
                    System.out.println(rs.getString(2));
                }

            } catch (SQLException e) {
                e.printStackTrace();
            }
            } catch (Exception e) {
                e.printStackTrace();
            }





    }

}
